#!/usr/bin/python
"""

soft_link.py
    --link LINK_PATH
    --target TARGET

	creates symbolic LINK which points to TARGET

"""

from optparse import OptionParser
import sys, os
import StringIO

# add self to search path for testing
if __name__ == '__main__':
    exe_path = os.path.split(os.path.abspath(sys.argv[0]))[0]
    sys.path.append(os.path.abspath(os.path.join(exe_path,"..", "python_modules")))
    myname = os.path.split(sys.argv[0])[1]
    myname = os.path.splitext(myname)[0];
else:
    myname = __name__





parser = OptionParser(version="%prog 1.0")
parser.add_option("-l", "--link", dest="link",
                  metavar="LINK_PATH", 
                  type="string",
                  help="Name and path of link to TARGET")
parser.add_option("-t", "--target", dest="target",
                  metavar="TARGET", 
                  type="string",
                  help="Name and path of file which will be soft linked.")

parser.set_defaults(target = "") 
parser.set_defaults(link = "") 

# get help string
f =StringIO.StringIO()
parser.print_help(f)
helpstr = f.getvalue()
(options, args) = parser.parse_args()

# mandatory options
if options.target == "":
    die_error("Please specify a file in --target.\n\n"+helpstr)
if options.link == "":
    die_error("Please specify a file in --link.\n\n"+helpstr)

os.symlink(os.path.abspath(options.target), os.path.abspath(options.link))
